package com.study.service;

import com.study.entity.User;
import com.study.mapper.UserMapper;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: chenhs
 * @date: Created in 15:54 2020/2/21
 **/
@Service
public class UserServiceImpl {

    @Autowired
    private UserMapper userMapper;


    public List<User> selectUsersByArray(int pageNo, int pageSize) {
        List<User> students = userMapper.selectUsersByArray();

        int firstIndex = (pageNo - 1) * pageSize;
        int lastIndex = pageNo * pageSize;

        return students.subList(firstIndex, lastIndex);
    }

    public List<User> selectUsersBySql(int pageNo, int pageSize) {
        Map<String, Object> data = new HashMap<>();
        data.put("pageNo", pageNo);
        data.put("pageSize", pageSize);
        return userMapper.selectUsersBySql(data);
    }

    public List<User> selectUsersByRowBounds(int start, int limit) {
        return userMapper.selectUsersByRowBounds(new RowBounds(start, limit));
    }

    public List<User> selectUsersByPage(Map<String, Object> map) {
        return userMapper.selectUsersByPage(map);
    }

    public int insertUser(User user) {
        return userMapper.user_insert(user);
    }

    public int deleteUser(User user) {
        return userMapper.user_delete(user);
    }

}
